package com.example.tellwin.mine.presenter;

import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.mine.bean.AttentionQuestionContentBean;
import com.example.tellwin.mine.bean.AttentionTeacherContentBean;
import com.example.tellwin.mine.contract.MineAttentionContract;
import com.example.tellwin.utils.ToastUtil;

import javax.inject.Inject;

/**
 * @author : LinZePeng
 * @date : 2020/12/4
 * @Describe ：
 **/
public class MineAttentionPresenter extends RxPresenter<MineAttentionContract.View> implements MineAttentionContract.Presenter<MineAttentionContract.View> {

    private TwjfApi mApi;

    public final int pageSize = 10;
    private int questionPages;
    private int questionPageNum;
    private boolean isNotMoreQuestion;
    private int teacherPages;
    private int teacherPageNum;
    private boolean isNotMoreTeacher;

    @Inject
    public MineAttentionPresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }


    @Override
    public void getAttentionQuestionList(boolean isLoadMore) {
        if(isLoadMore){
            if (isNotMoreQuestion) {
                return;
            }
            if (questionPages != 0 && questionPageNum == questionPages) {
                ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                isNotMoreQuestion = true;
                return;
            }
            questionPageNum++;
        }else {
            questionPageNum = 1;
            questionPages = 0;
            isNotMoreQuestion = false;
        }

        mApi.getAttentionQuestionList("1" , questionPageNum+"",pageSize+"", new SimpleCallback<AttentionQuestionContentBean>(mView) {
            @Override
            public void onSuccess(AttentionQuestionContentBean attentionQuestionContentBean) {
                questionPageNum = attentionQuestionContentBean.getPageNum();
                questionPages = attentionQuestionContentBean.getPages();
                if (attentionQuestionContentBean.getMyFollowList() == null || attentionQuestionContentBean.getMyFollowList().size() == 0) {
                    ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                    isNotMoreQuestion = true;
                    return;
                }
                mView.attentionQuestionListResult(isLoadMore , attentionQuestionContentBean.getMyFollowList());

            }

            @Override
            public void onFail(String msg) {

            }
        });
    }

    @Override
    public void getAttentionTeacherList(boolean isLoadMore) {
        if(isLoadMore){
            if (isNotMoreTeacher) {
                return;
            }
            if (teacherPages != 0 && teacherPageNum == teacherPages) {
                ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                isNotMoreTeacher = true;
                return;
            }
            teacherPageNum++;
        }else {
            teacherPageNum = 1;
            teacherPages = 0;
            isNotMoreTeacher = false;
        }

        mApi.getAttentionTeacherList("2" , teacherPageNum+"",pageSize+"", new SimpleCallback<AttentionTeacherContentBean>(mView) {
            @Override
            public void onSuccess(AttentionTeacherContentBean attentionQuestionContentBean) {
                teacherPageNum = attentionQuestionContentBean.getPageNum();
                teacherPages = attentionQuestionContentBean.getPages();
                if (attentionQuestionContentBean.getMyFollowList() == null || attentionQuestionContentBean.getMyFollowList().size() == 0) {
                    ToastUtil.show(MainApplication.getCurActivity(), R.string.none_data);
                    isNotMoreTeacher = true;
                    return;
                }
                mView.attentionTeacherListResult(isLoadMore , attentionQuestionContentBean.getMyFollowList());
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }
}
